//
//  LXContainerView.swift
//  LXPageView
//
//  Created by seven on 2017/11/9.
//  Copyright © 2017年 seven. All rights reserved.
//

import UIKit

class LXContainerView: UIView {
    
    private var titles: [String]
    private var childVcs: [UIViewController]
    private var parentVc: UIViewController
    private var style: LXTitleStyle
    private var titleView: LXTitleView!
    
    init(frame: CGRect,titles: [String], childVcs: [UIViewController], parentVc: UIViewController, style: LXTitleStyle) {
        self.titles = titles
        self.childVcs = childVcs
        self.parentVc = parentVc
        self.style = style
        
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

//MARK:- 设置UI界面
extension LXContainerView{
    private func setupUI(){
        setupTitleView()
        setupContentView()
    }
    private func setupTitleView(){
        let titleFrame = CGRect(x: 0, y: 0, width: bounds.width, height: style.titleHeight)
        titleView = LXTitleView(frame: titleFrame, titles: titles, style: style)
        titleView.backgroundColor = UIColor.randomColor()
        addSubview(titleView)
    }
    private func setupContentView(){
        let contentFrame = CGRect(x: 0, y: titleView.frame.maxY, width: bounds.width, height: bounds.height - titleView.frame.maxY)
        let contentView = LXContentView(frame: contentFrame, childVcs: childVcs, parentVc: parentVc)
        addSubview(contentView)
        
        ///ContentView相互成为titleView的代理
        titleView.delegete = contentView
        contentView.delegete = titleView
    }
}

